home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE13 / VALIDAT / UNIT1.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1996-06-14  |  2.2 KB  |  84 lines

  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, DBTables, DB, StdCtrls, Mask, DBCtrls, ExtCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     DBEdit1: TDBEdit;
  12.     Table1: TTable;
  13.     DataSource1: TDataSource;
  14.     Table1LAST_NAME: TStringField;
  15.     Table1FIRST_NAME: TStringField;
  16.     Table1ACCT_NBR: TFloatField;
  17.     Table1ADDRESS_1: TStringField;
  18.     Table1CITY: TStringField;
  19.     Table1STATE: TStringField;
  20.     Table1ZIP: TStringField;
  21.     Table1TELEPHONE: TStringField;
  22.     Table1DATE_OPEN: TDateField;
  23.     Table1SS_NUMBER: TFloatField;
  24.     Table1PICTURE: TStringField;
  25.     Table1BIRTH_DATE: TDateField;
  26.     Table1RISK_LEVEL: TStringField;
  27.     Table1OCCUPATION: TStringField;
  28.     Table1OBJECTIVES: TStringField;
  29.     Table1INTERESTS: TStringField;
  30.     Table1IMAGE: TBlobField;
  31.     DBNavigator1: TDBNavigator;
  32.     procedure FormCreate(Sender: TObject);
  33.     procedure Table1BIRTH_DATEValidate(Sender: TField);
  34.     procedure Table1BeforePost(DataSet: TDataset);
  35.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  36.   private
  37.     { Private declarations }
  38.   public
  39.     { Public declarations }
  40.   end;
  41.  
  42. var
  43.   Form1: TForm1;
  44.  
  45. implementation
  46.  
  47. {$R *.DFM}
  48.  
  49. procedure TForm1.FormCreate(Sender: TObject);
  50. begin
  51.   Table1.Open
  52. end;
  53.  
  54. procedure TForm1.Table1BIRTH_DATEValidate(Sender: TField);
  55. begin
  56.   if (Sender AS TDateField).Value > Now then
  57.     raise Exception.Create('Birthday is a future date...')
  58. end;
  59.  
  60. procedure TForm1.Table1BeforePost(DataSet: TDataset);
  61. begin
  62.   if {(DataSet.FieldByName('NUMBER_OF_CHILDREN').AsInteger > 0) and}
  63.     ((Now - DataSet.FieldByName('BIRTH_DATE').AsDateTime) < (12 * 365)) then
  64.     raise Exception.Create('Birthday inconsistent with number of children...')
  65. end;
  66.  
  67. procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  68. var Result: Word;
  69. begin
  70.   if Table1.State in [dsEdit,dsInsert] then
  71.   begin
  72.     Result := MessageDlg('Save Changes to '+Table1.TableName+'?',
  73.                           mtConfirmation, [mbYes, mbNo, mbCancel], 0);
  74.     CanClose := True;
  75.     case Result of
  76.       MrYes: Table1.Post;
  77.        MrNo: Table1.Cancel;
  78.    MrCancel: CanClose := False
  79.     end
  80.   end
  81. end;
  82.  
  83. end.
  84.